﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using r4u.business.logic.layer.RECRUIT;

namespace r4u.Controllers
{
    public class ApplicantController : Controller
    {

        public ActionResult List(int id)
        {
            Vacancy temp = new Vacancy();
            Candidate[] candidates = temp.GetApplicants(id.ToString());


            if (User.IsInRole("TRIAL"))
            {
                candidates = candidates.Take(5).ToArray();

                if (candidates != null && candidates.Length > 0)
                {
                    candidates[0].Trial = "TRIAL";
                }
            }
        


            var settings = new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            var jsonResult = new ContentResult
            {
                Content = JsonConvert.SerializeObject(candidates, settings),
                ContentType = "application/json"
            };
            return jsonResult;
        }

    }
}
